<!--
 * @version: 
 * @Author: yu
 * @Date: 2023-06-26 16:04:07
 * @LastEditors: Andy
 * @LastEditTime: 2023-07-01 22:29:04
-->
<template>
    <div>
        <el-container>
            <el-aside width="200px">
                <!-- default-active  当前激活菜单的 index   unique-opened  是否只保持一个子菜单的展开-->
                <el-menu :default-active="defaultActive" background-color="#20222a" text-color="#fff"
                    active-text-color="#ffd04b" router collapse-transition unique-opened>

                    <el-menu-item index="/index/home">
                        <i class="el-icon-menu"></i>
                        <span slot="title">首页</span>
                    </el-menu-item>
                    <!-- 动态绑定 -->
                    <template v-if="user">
                        <template v-for="item in user.menus">
                            <el-submenu v-if="item.children" :key="item.id" :index="item.title">
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{ item.title }}</span>
                                </template>
                                <el-menu-item v-for="i in item.children" :key="i.id" :index="'/index/' + i.url">{{ i.title
                                }}</el-menu-item>
                            </el-submenu>
                            <!-- 没有children字段的 -->
                            <el-menu-item v-else :key="item.id" :index="'/index/' + item.url">{{ item.title
                            }}</el-menu-item>
                        </template>
                    </template>

                    <!-- 静态绑定 -->
                    <!-- <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-setting"></i>
                            <span>系统管理</span>
                        </template>
                        <el-menu-item index="/index/menu">菜单管理</el-menu-item>
                        <el-menu-item index="/index/role">角色管理</el-menu-item>
                        <el-menu-item index="/index/member">管理员管理</el-menu-item>
                    </el-submenu>

                    <el-submenu index="3">
                        <template slot="title">
                            <i class="el-icon-s-goods"></i>
                            <span>商城管理</span>
                        </template>
                        <el-menu-item index="/index/cate">商品分类</el-menu-item>
                        <el-menu-item index="/index/specs">商品规格</el-menu-item>
                        <el-menu-item index="/index/goods">商品管理</el-menu-item>
                        <el-menu-item index="/index/user">会员管理</el-menu-item>
                        <el-menu-item index="/index/banner">轮播图管理</el-menu-item>
                        <el-menu-item index="/index/seckill">秒杀活动</el-menu-item>
                    </el-submenu> -->

                </el-menu>
            </el-aside>
            <el-container>
                <el-header>
                    <span v-if="user">{{ user.username }}</span>
                    <el-button @click="quit" type="success">退出</el-button>
                </el-header>
                <el-main>
                    <el-breadcrumb separator-class="el-icon-arrow-right">
                        <el-breadcrumb-item :to="{ path: '/index/home' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item>{{ $route.name }}</el-breadcrumb-item>
                    </el-breadcrumb>
                    <!-- 二级路由出口 -->
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
import { successAlert } from '@/utils/alert'
export default {
    data() {
        return {
            defaultActive: "/home"
        }
    },
    methods: {
        ...mapActions({
            requestUser: 'userActions'
        }),
        //退出
        quit() {
            //清除缓存
            this.requestUser(null)
            //消息提示
            successAlert('退出成功')
            //路由跳转
            this.$router.push('/login')
        }
    },
    mounted() {
        this.defaultActive = this.$route.path
        // console.log(this.$route);
        document.title = this.$route.meta.title
    },
    watch: {},
    computed: {
        ...mapGetters({
            user: 'user'
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped>
/* .el-breadcrumb{
    margin-bottom: 15px;
} */
.el-header {
    background-color: #B3C0D1;
    color: #333;
    text-align: right;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
    height: 100vh;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
}
</style>